package JavaSEAdvance.day05_API;

import java.math.BigDecimal;

/**
 * @author Xiao
 * @date 2021/7/21
 */
public class d503_BigDecimalDemo {
    /**
     * BigDecimal
     */
    public static void main(String[] args) {
        BigDecimal bd1 = new BigDecimal("3.0");
        BigDecimal bd2 = new BigDecimal("4.0");
        System.out.println(bd1.add(bd2));
        System.out.println(bd1.subtract(bd2));
        System.out.println(bd1.multiply(bd2));
        System.out.println(bd1.divide(bd2));
        System.out.println("---------");
        BigDecimal bd3 = new BigDecimal("10.0");
        BigDecimal bd4 = new BigDecimal("3.0");
//        System.out.println(bd3.divide(bd4));    //ArithmeticException
        System.out.println(bd3.divide(bd4,2,BigDecimal.ROUND_UP));      //进一法
        System.out.println(bd3.divide(bd4,2,BigDecimal.ROUND_FLOOR));      //去尾法
        System.out.println(bd3.divide(bd4,2,BigDecimal.ROUND_HALF_UP));      //四舍五入法
    }
}
